<?php
// 解析车间
function cj($val){
	switch ($val)
		{
		case "zp1":
			  $cj="装配一车间";
			  break;
			case "zp2":
			  $cj="装配二车间";
			  break;
			case "sz1":
			  $cj="试制一车间";
			  break;
			case "sz2":
			  $cj="试制二车间";
			  break;
			case "ts":
			  $cj="调试车间";
			case "ns":
			  $cj="内饰车间";
			  break;
			  case "yl":
			  $cj="预留区";
			  break;
		}
		return $cj;
}
// 解析班次

function banci($val){
    switch ($val)
    {
        case "day":
            $bc="白班";
            break;
        case "night":
            $bc="夜班";

        default:
            $bc="白班";
    }
    return $bc;
}
//<option value="1">三检</option>
//                    <option value="2">三不</option>
//                    <option value="3">三按</option>

function  leibies($val){
    $data=array('','三检','三不','三按');

    return $data[$val];
}
//<option value="0" selected="selected">/</option>
//                                <option value="1">X3000专项</option>
//                                <option value="2">载货车专项</option>
//                                <option value="3">大模块水箱问题</option>
//                                <option value="4">中联重科专项</option>
//                                <option value="5">三一重工专项</option>
//                                <option value="6">中石油专项</option>
//                                <option value="7">非专项填写</option>

function  laiyuans($val){
    $data=array('','X3000专项','载货车专项','大模块水箱问题','中联重科专项','三一重工专项','中石油专项','非专项填写');

    return $data[$val];
}

function  chongfu($val){
    $data=array('','非','是');

    return $data[$val];
}


function  dws($val){
    $data=array('','一工段','二工段');

    return $data[$val];
}

function xiangmu($val){

    $data=array('','管路打折','错漏装','三漏问题','外观质量问题','松装（力矩不足、力矩未检测）','未做标记（标记不规范)','未执行“三按”','一致性','缺捆扎、固定','其它','干涉','间隙小','装调问题');

    return $data[$val];
}
// 解析平台

 function pt($val){
 	switch ($val)
		{
		case "F3000":
	  $pt="F3000	";
	  break;
	  	case "M3000":
	   $pt="M3000";
	  break;
	 case "X3000":
	   $pt="X3000";
	  break;
	case "STR":
	   $pt="奥龙";
	  break;
	case "PZ":
	   $pt="偏置";
	  break;
	  case "KY":
	   $pt="矿用";
	  break;
	  case "QT":
	   $pt="其他";
	  break;
	    case "JUN":
	   $pt="军车";
	  break;


	default:
	    $pt="其他";
	}
	return  $pt;
}
// 解析车辆类型

 function cx($val){
 	switch ($val)
		{
		case "1":
	  $cx="越野车";
	  break;
	case "2":
	  $cx="自卸车";
	  break;
	case "3":
	  $cx="自卸车";
	  break;
	case "4":
	  $cx="牵引车";
	  break;
	case "5":
	  $cx="专用车";
	  break;
	  case "6":
	  $cx="其他";
	  break;

	default:
	   $cx="其他";
	}
	return  $cx;
}
// 解析问题类别

 function leibie($val){
 	switch ($val)
		{

	case "lbj":
	  $lb="零部件";
	  break;
	 case "sj":
	  $lb="设计";
	  break;
	case "gy":
	  $lb="工艺";
	  break;
	case "zp":
	  $lb="装配";
	  case "bzj":
	  $lb="标准件";
	  break;


	default:
	   $lb="其他";
	}
	return  $lb;
}

// 6位流水号补零
function ling($str){
	 // var n=6-a.length;
  //         var re="";
  //         for(var i=0;i<n;i++){
  //             re=re+'0';
  //         }
  //         return re;
	$n=6-strlen($str);
	for($i=0;$i<$n;$i++){
		$str="0".$str;
	}

	return $str;
}

function xieyi($str){
	// if(preg_match('/(\d{4}[\s-(（]*军?协议\s?\S*\s?\/)|(\d{4}[\s-(（]*民?协议\s?\S*\s?\/)/i', $str, $matches)) {
	if(preg_match('/(\d{4}[\s-(（《<]*军?协议[\s-)）]*[^\/]*)|(\d{4}[\s-(（>》]*民?协议[\s-)）]*[^\/]*)/i', $str, $matches)) {
	// \d{4}[\s-(（]*军?协议[\s-)）]*[^\/]*
// if(preg_match('/\d*[\s-(（]*军?协议[\s-)）]*\d*[^/]*/i', $str, $matches)) {
	// \d*[\s-(（]*[军民]?协议[\s-)）]*\d*[^/]*
	    $xy=explode('/',$matches[0]);
	return $xy[0];
	}else{
		return "";
	}
}

function GrabImage($url, $dir, $filename=''){
    if(empty($url)){
        return false;
    }
    $ext = strrchr($url, '.');
    if($ext != '.gif' && $ext != ".jpg" && $ext != ".bmp"&& $ext != ".png"){
        echo "格式不支持！";
        return false;
    }

    $dir = realpath($dir);
    //目录+文件
    $filename = (empty($filename) ? '/'.time().''.$ext : '/'.$filename);
    $filename = $dir . $filename;
    //开始捕捉
    ob_start();
    readfile($url);
    $img = ob_get_contents();
    ob_end_clean();
    $size = strlen($img);
    $fp2 = fopen($filename , "a");
    fwrite($fp2, $img);
    fclose($fp2);
    return $filename;
}

function folderToZip($folder, &$zipFile, $subfolder = null) {
    if ($zipFile == null) {
        // no resource given, exit
        return false;
    }
    // we check if $folder has a slash at its end, if not, we append one
    $folder .= end(str_split($folder)) == "/" ? "" : "/";
    $subfolder .= end(str_split($subfolder)) == "/" ? "" : "/";
    // we start by going through all files in $folder
    $handle = opendir($folder);
    while ($f = readdir($handle)) {
        if ($f != "." && $f != "..") {
            if (is_file($folder . $f)) {
                // if we find a file, store it
                // if we have a subfolder, store it there
                if ($subfolder != null)
                    $zipFile->addFile($folder . $f, $subfolder . $f);
                else
                    $zipFile->addFile($folder . $f);
            } elseif (is_dir($folder . $f)) {
                // if we find a folder, create a folder in the zip
                $zipFile->addEmptyDir($f);
                // and call the function again
                folderToZip($folder . $f, $zipFile, $f);
            }
        }
    }
}

/**
 * 将非GBK字符集的编码转为GBK
 *
 * @param mixed $mixed 源数据
 *
 * @return mixed GBK格式数据
 */
function charsetToGBK($mixed)
{
    if (is_array($mixed)) {
        foreach ($mixed as $k => $v) {
            if (is_array($v)) {
                $mixed[$k] = charsetToGBK($v);
            } else {
                $encode = mb_detect_encoding($v, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
                if ($encode == 'UTF-8') {
                    $mixed[$k] = iconv('UTF-8', 'GBK', $v);
                }
            }
        }
    } else {
        $encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
        //var_dump($encode);
        if ($encode == 'UTF-8') {
            $mixed = iconv('UTF-8', 'GBK', $mixed);
        }
    }
    return $mixed;
}


/**
 * 将非UTF-8字符集的编码转为UTF-8
 *
 * @param mixed $mixed 源数据
 *
 * @return mixed utf-8格式数据
 */
function charsetToUTF8($mixed)
{
    if (is_array($mixed)) {
        foreach ($mixed as $k => $v) {
            if (is_array($v)) {
                $mixed[$k] = charsetToUTF8($v);
            } else {
                $encode = mb_detect_encoding($v, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
                if ($encode == 'EUC-CN') {
                    $mixed[$k] = iconv('GBK', 'UTF-8', $v);
                }
            }
        }
    } else {
        $encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
        if ($encode == 'EUC-CN') {
            $mixed = iconv('GBK', 'UTF-8', $mixed);
        }
    }
    return $mixed;
}

